package com.music.test;

import com.alibaba.fastjson.JSON;
import com.music.MusicApplicationTests;
import com.music.config.MinioConfig;
import com.music.utils.file.MinioUtil;
import io.minio.MinioClient;
import io.minio.RemoveObjectArgs;
import io.minio.errors.*;
import org.junit.Test;


import javax.annotation.Resource;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.*;

public class test extends MusicApplicationTests {
    @Resource
    private MinioConfig minioConfig;
    @Resource
    private MinioClient client;
    private final MinioUtil minioUtil = MinioUtil.getInstance();

    @Test
    public void test1() throws Exception {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar begin = Calendar.getInstance();
        begin.set(2021, 7, 8);
        List<Date> day = new ArrayList<>();
        day.add(begin.getTime());
        while (begin.get(Calendar.YEAR) != 2022 || begin.get(Calendar.MONTH) != 0 || begin.get(Calendar.DATE) != 20) {
            begin.add(Calendar.DATE, 1);
            day.add(begin.getTime());
        }

        Calendar cal = Calendar.getInstance();
        Map<Integer, Map<Integer, String>> calendarMap = new HashMap<>();
        Integer weekCount = 1;
        Map<Integer, String> map = new HashMap<>();
        for (Date date : day) {
            System.out.println(format.format(date));
            cal.setTime(date);
            System.out.println(cal.get(Calendar.DAY_OF_WEEK));
            map.put(cal.get(Calendar.DAY_OF_WEEK), format.format(date));
            calendarMap.put(weekCount, map);
            if (cal.get(Calendar.DAY_OF_WEEK) == 7) {
                map = new HashMap<>();
                weekCount++;
            }
        }
        System.out.println(JSON.toJSONString(calendarMap));
    }
    @Test
    public void test3() throws IOException, InvalidKeyException, InvalidResponseException, InsufficientDataException, NoSuchAlgorithmException, ServerException, InternalException, XmlParserException, ErrorResponseException {
        RemoveObjectArgs args = RemoveObjectArgs.builder()
                .bucket(minioConfig.getBucketName())
                .object("image/c2fdfc039245d6889c25ff0caac27d1ed21b2476.jpg")
                .build();
        client.removeObject(args);
    }
}

//    @Test
//    public void test2(List<Date> days) throws Exception {
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
//        Calendar cal = Calendar.getInstance();
//        Map<Integer, Map<Integer, Date>> calendarMap = new HashMap<>();
//        Integer weekCount = 1;
//        for (Date date : days) {
//            cal.setTime(date);
//            Map<Integer, Date> map = new HashMap<>();
//            map.put(cal.get(Calendar.DAY_OF_WEEK), date);
//            calendarMap.put(weekCount, map);
//            if (cal.get(Calendar.DAY_OF_WEEK) == 7)
//                weekCount++;
//        }
//        System.out.println(JSON.toJSONString(calendarMap));
//    }
//}
